﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Cinemax.DTO;
namespace Cinemax.DAO
{
    public class TaiKhoanDAO
    {
        static rapphimDataContext data = new rapphimDataContext();
        public static int CheckLogin(string username, string password)
        {
            int id = -1;
            try
            {
                id = data.SP_CHECK_LOGIN(username, password).ElementAt(0).MaTaiKhoan;
            }
            catch (Exception)
            {
                id = -1;
            }
            return id;
        }

        public static string GetUsernameByID(int id)
        {
            string username = string.Empty;
            try
            {
                username = data.SP_GET_CUSTOMER_USERNAME(id).ElementAt(0).TenDangNhap;
            }
            catch (Exception)
            {
                username = string.Empty;
            }
            return username;
        }

        public static int GetPointByID(int id)
        {
            int point = 0;
            try
            {
                point = data.SP_GET_POINT_BYID(id).ElementAt(0).SoDiemThuong.Value;
            }
            catch (Exception)
            {
                point = 0;
            }
            return point;
        }

        public static int Register(string username, string pass, string name, string add, string email, string phone)
        {
            int result = -1;
            result = data.DangKiTaiKhoan(username, pass, name, add, email, phone);
            return result;
        }

        public static TaiKhoanDTO getInfoByID(int id)
        {
            TaiKhoanDTO tk = new TaiKhoanDTO();
            GET_INFO_BYIDResult tkps = new GET_INFO_BYIDResult();
            tkps = data.GET_INFO_BYID(id).ElementAt(0);
            tk = new TaiKhoanDTO(tkps);
            return tk;
        }
    }
}